function loadData(){

    $("#jqGrid").jqGrid({
        url:base+ '/rule/view/list',
        datatype: "json",
        styleUI : 'Bootstrap',
        colNames:['名称','编码','表达式', '创建人', '创建时间','描述','<div align="center" >操作</div>'],
        colModel: [
            {name:'name',index:'name', sortable:false},
            {name:'code',index:'code'},
            {name:'expression',index:'expression', sortable:false},
            {name:'createBy',index:'createBy', sortable:false},
            {name:'createTime',index:'createTime',formatter:tools.formatDate, sortable:false},
            {name:'description',index:'description', sortable:false},
            {name:'id',index:' ',align:'center', sortable:false,formatter : function(value, options, rData){
                return "<a href='javascript:void(0)' onclick=doEdit(\""+value+"\")><span class='btn btn-sm purple'>编辑</span></a>"
            }}
        ],
        viewrecords: true,
        // width:'990',
        autowidth:true,
        height:'auto',
        // forceFit:true,
        // shrinkToFit: false,
        rowNum: 10,
        rowList : [5,10,15],

        multiselect: true,
        pager: "#jqGridPager"

    });


}



function doEdit(id) {
    var url = base+ "/rule/uc/edit?id=" + id + "&type=edit";
    window.location.href=url;
}

function doAdd(id) {
    var url =base+ "/rule/uc/edit?id=" + id + "&type=add";
    window.location.href=url;
}


/**
 *删除
 */
function doDelete() {
    var ids=$('#jqGrid').jqGrid('getGridParam','selarrrow');
    if (ids.length<=0) {
        $.messager.alert("请选择需要删除的数据项");
        return;
    }
    var url =base+"/rule/dh/delete";
    $.messager.confirm("你确定要删除选中的记录吗?", function (ck) {
        if(ck){
            $.post(url, {ids: ids}, function (data) {
                $.messager.alert0({selector: "#indexAlert", type: data.code, html: data.message});
                if (data && data.code == 'SUCCESS') {
                   $("#jqGrid").trigger("reloadGrid");
                }
            });
        }})
}


function doSubmit(type) {
    if (!formCheck().form()) {
        return;
    }
    var url;
    if ("add" == type) {
        url = base + "/rule/sk/insert";
    } else {
        url = base + "/rule/uc/update";
    }
    $.post(url, $("#editForm").serialize(), function (data) {
        $.messager.alert0({selector: "#editAlert", type: data.code, html: data.message});
        if (data && data.code == 'SUCCESS') {
            tools.goto(base + "/rule/view/index", 500);
        }
    }, "json");

}

function formCheck() {
    return $('#editForm').validate({
        rules: {
            expression: {
                maxlength:[24],
                required:true
            },
            code: {
                maxlength:[8],           
                required:true
            },
            name: {
                maxlength:[24],
                required:true
            }
        }
    });
}


/**查询*/
function doSearch(){
    var expression=$("input[name=expression]").val();
    var code=$("input[name=code]").val();
    var name=$("input[name=name]").val();
    $("#jqGrid").jqGrid('setGridParam',{
        datatype:'json',
        postData:{'expression':expression,'code':code,'name':name}, //发送数据
        page:0
    }).trigger("reloadGrid"); //重新载入
}
